package com.qf.cx.simplenms.tagmemory.model;

public class TagMemoryModel {
	public final String name;
	public final int bank;
	public final int offset;
	public final int length;

	public TagMemoryModel(String name, int bank, int offset, int length) {
		super();
		this.name = name;
		this.bank = bank;
		this.offset = offset;
		this.length = length;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + bank;
		result = prime * result + length;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + offset;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		TagMemoryModel other = (TagMemoryModel) obj;
		if (bank != other.bank) {
			return false;
		}
		if (length != other.length) {
			return false;
		}
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		if (offset != other.offset) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "TagMemory [name=" + name + ", bank=" + bank + ", offset=" + offset + ", length=" + length + "]";
	}

	public static class Identifier {
		public final TagMemoryModel tm;
		public final String key;

		public Identifier(TagMemoryModel tm, String key) {
			super();
			this.tm = tm;
			this.key = key;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((key == null) ? 0 : key.hashCode());
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Identifier other = (Identifier) obj;
			if (key == null) {
				if (other.key != null)
					return false;
			} else if (!key.equals(other.key))
				return false;
			return true;
		}

	}

	public Identifier indentifier() {
		return new Identifier(this, bank + "-" + offset + "-" + length);
	}

}
